var Workport = Workport || {};
// API utility
Workport.APIUtil = (function(){
    return {
        getUrl:function (/*index, class, replace1, replace2, ...*/) {
            var index, i, loops, r, c;
            loops = arguments.length;
            if (loops > 1) {
                index = arguments[0];
                c = arguments[1];
                r = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + c.name + c.urls[index];
                for (i = 2; i < loops; i++)
                    r = r.replace("{"+(i-1)+"}", arguments[i]);
            }
            return r;
        },
        sendRequest:function (method,url,callback,query,sync,data){
            if(method == 'get'){
                if(sync){
                    return sfw.Http.syncGet(url,callback,query);
                } else {
                    return sfw.Http.get(url,callback,query);
                }
            } else if(method == 'post'){
                if(sync){
                    return sfw.Http.syncPost(url,callback,query,data);
                } else {
                    return sfw.Http.post(url,callback,query,data);
                }
            } else if(method == 'put'){
                if(sync){
                    return sfw.Http.syncPut(url,callback,query,data);
                } else {
                    return sfw.Http.put(url,callback,query,data);
                }
            } else if(method == 'del'){
                if(sync){
                    return sfw.Http.syncDel(url,callback,query,data);
                } else {
                    return sfw.Http.del(url,callback,query,data);
                }
            } 
        }
    }
})();

// @Path("/Alert")
Workport.AlertAPI = (function(){

    var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'Alert/';

    var urls = ["", "Reset", "AlertCount" ];

    function getUrl(/*index, replace1, replace2, ...*/) {
        var index, i, loops, r;
        loops = arguments.length;
        if (loops > 0) {
            index = arguments[0];
            r = root + urls[index];
            for (i = 1; i < loops; i++)
                r = r.replace("{"+i+"}", arguments[i]);
        }
        return r;
    }

    return {
        // @GET  @Path("/")
        // public AlertResponse GetUserAlertNotification()
        // getAlert:function(handler,request){
        // 	var domain = {};
        // 	domain.ps = request.pageSize;
        // 	if(request.offset){
        // 		domain.offset = request.offset;
        // 	}
        // 	return sfw.Http.get(getUrl(0),function(xhr,data){
        // 		if (!sfw.Http.handleError(xhr, data)) {
        // 			if(jQuery.isFunction(handler)){
        // 				handler(data, xhr);
        // 			}
        // 		}
        // 	},domain);
        // },
        // @PUT	@Path("/Reset")
        // public BasicResponse DeleteAlertNotificationHistory()
        resetAlert:function(handler){
            return sfw.Http.put(getUrl(1),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            });
        },
        // @DELETE	@Path("/Reset")
        // public BasicResponse DeleteAlertNotificationHistory()
        deleteAlert:function(handler){
            return sfw.Http.del(getUrl(1),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            });
        },
        // @GET	@Path("/AlertCount")
        // public AlertCountResponse GetUserAlertNotificationCount()
        // countAlert:function(handler){
        // 	return sfw.Http.get(getUrl(2),function(xhr,data){
        // 		if (!sfw.Http.handleError(xhr, data)) {
        // 			if(jQuery.isFunction(handler)){
        // 				handler(data, xhr);
        // 			}
        // 		}
        // 	});
        // }
    }
})();
//@Path("/Apps")
Workport.AppAPI = (function(){
    var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'Apps/';

    var urls = ["Register", "HomeApps", "AppsList", "HomeSearch", "Search", "{1}/AppDetailsById",
        "PendingApprovalCount", "EditApps", "{1}/EditAppDetails", "Delete", "PendingApprovalApps",
        "Approval", "{1}/AddFavourite", "SaveLike", "{1}/LikedUsers", "LaunchCount","{1}/ShowFeedbacks",
        "SaveFeedback", "EditCount"];

    function getUrl(/*index, replace1, replace2, ...*/) {
        var index, i, loops, r;
        loops = arguments.length;
        if (loops > 0) {
            index = arguments[0];
            r = root + urls[index];
            for (i = 1; i < loops; i++)
                r = r.replace("{"+i+"}", arguments[i]);
        }
        return r;
    }

    return {
        // @POST		@Path("/Register")
        // public BasicResponse PostRegisterApp(RegisterAppRequest request)
        registerApp:function(handler,request){
            return sfw.Http.post(getUrl(0),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                AppId          : request.appId,
                AppTitle       : request.title,
                AppDescription : request.description,
                AppImage       : request.image,
                AppURL         : request.url,
                Mode           : request.mode,
                IsModified     : request.modified
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET 	@Path("/HomeApps")
        // public HomeAppResponse GetHomeApps()
        getHomeApp:function(handler,request){
            return sfw.Http.get(getUrl(1),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)){
                    if(jQuery.isFunction(handler)){
                        handler(data,xhr);
                    }
                }
            },{
                Offset:request.offset,
                Count:request.count,
                Mode:request.mode,
                FilterBy:request.filterBy ? request.filterBy:"0",
                OrderBy:request.orderBy ? request.orderBy :"0"
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/AppsList")
        // public AppResponse GetApps()
        getAllApp:function(handler,request){
            return sfw.Http.get(getUrl(2),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data,xhr);
                    }
                }
            },{
                Offset:request.offset,
                Count:request.count,
                FilterBy:request.filterBy,
                orderBy:request.orderBy,
                Mode:request.mode
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/HomeSearch")
        // public HomeAppResponse GetHomeAppsSearchResult()
        searchHomeApp:function(handler,request){
            return sfw.Http.get(getUrl(3),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                Offset:request.offset ? request.offset : 0,
                Count:request.count != undefined ? request.count : 10,
                SearchText:request.key,
                OrderBy:request.orderBy,
                Filtermode:request.mode
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/Search")
        // public AppResponse GetAppsSearchResult()
        searchAllApp:function(handler,request){
            return sfw.Http.get(getUrl(4),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                Offset:request.offset?request.offset:0,
                Count:request.count != undefined ? request.count:10,
                SearchText:request.key,
                OrderBy:request.orderBy,
                Filtermode:request.mode
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/{appId}/AppDetailsById")
        // public AppDetailResponse GetAppDetailsByID()
        getDetail:function(handler,request){
            return sfw.Http.get(getUrl(5,request.appId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/PendingApprovalCount")
        // public AppPendingResponse GetPendingApprovalAppsCount()
        getPendingCount:function(handler){
            return sfw.Http.get(getUrl(6),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/EditApps")
        // public AppEditResponse GetAppsforEdit()
        getEditApp:function(handler,request){
            return sfw.Http.get(getUrl(7),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                Offset:request.offset ? request.offset : 0,
                Count:request.count != undefined ? request.count : 10,
                Sort:request.sort
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/{appId}/EditAppDetails")
        // public AppEditDetailResponse GetEditAppDetails(@PathParam("appId")String appId)
        getEditDetail:function(handler,request){
            return sfw.Http.get(getUrl(8,request.appId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            });
            function toViewModel(data){
                return data;
            }
        },
        // @POST	@Path("/Delete")
        // public BasicResponse DeleteOrCopy(AppActionRequest request)
        deleteApp:function(handler,request){
            return sfw.Http.post(getUrl(9),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                AppId  : request.appId,
                Action : request.action
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/PendingApprovalApps")
        // public AppApprovalResponse GetPendingApprovalApps()
        getPendingApproval:function(handler,request){
            return sfw.Http.get(getUrl(10),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                PageNo:request.pageNo,
                PageSize:request.pageSize,
                Sort:request.sort
            });
            function toViewModel(data){
                return data;
            }
        },
        // @POST	@Path("/Approval")
        // public BasicResponse PostApproverAction(AppActionRequest request)
        approvalApp:function(handler,request){
            return sfw.Http.post(getUrl(11),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                AppId  : request.appId,
                Action : request.action
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/{appId}/AddFavourite")
        // public AddFavouriteResponse GetAddFavourite(@PathParam("appId")String appId)
        addFavourite:function(handler,request){
            return sfw.Http.get(getUrl(12,request.appId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            });
            function toViewModel(data){
                return data;
            }
        },
        // @POST		@Path("/SaveLike")
        // public AppLikeResponse PostLike(AppLikeRequest request)
        saveLike:function(handler,request){
            return sfw.Http.post(getUrl(13),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                AppId : request.appId
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/{appId}/LikedUsers")
        // public AppLikeUserResponse GetAllLikedusers(@PathParam("appId")String appId)
        getLikeUser:function(handler,request){
            return sfw.Http.get(getUrl(14,request.appId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                Offset : request.offset,
                Count  : request.count
            });
            function toViewModel(data){
                return data;
            }
        },
        // @POST		@Path("/LaunchCount")
        // public AppLaunchCountResponse PostAddLaunchCount(AppLaunchCountRequest request)
        postLaunchCount:function(handler,request){
            return sfw.Http.post(getUrl(15),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                AppId : request.appId
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET 	@Path("/{appId}/ShowFeedbacks")
        // public AppFeedbackDetailResponse GetFeedbackDetails(@PathParam("appId")String appId)
        showFeedback:function(handler,request){
            return sfw.Http.get(getUrl(16,request.appId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                Offset  : request.offset,
                Count   : request.count,
                AppType : request.type
            });
            function toViewModel(data){
                return data;
            }
        },
        // @POST	@Path("/SaveFeedback")
        // public AppFeedbackSaveResponse PostFeedback(AppFeedbackRequest request)
        saveFeedback:function(handler,request){
            return sfw.Http.post(getUrl(17),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                AppId : request.appId,
                FeedbackComments : request.feedback,
                Ratings : request.ratings
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/EditCount")
        // public AppCountResponse GetEditAppCount()
        getStatus:function(handler){
            return sfw.Http.get(getUrl(18),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            });
            function toViewModel(data){
                return data;
            }
        }
    }
})();

// @Path("/Alert")
Workport.CommunityAPI = (function(){

    var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'Community';

    var urls = ["", "/{1}", "/{1}/Membership", "/Membership", "/Subscribe", "/Search", "/{1}/Expert", "/Nominate", "/CommunityStats", "/New",
        "/{1}/Exist", "/Types", "/{1}/Edit", "{1}/Export" ];

    function getUrl(/*index, replace1, replace2, ...*/) {
        var index, i, loops, r;
        loops = arguments.length;
        if (loops > 0) {
            index = arguments[0];
            r = root + urls[index];
            for (i = 1; i < loops; i++){
                r = r.replace("{"+i+"}", arguments[i]);
            }
        }
        return r;
    }

    function sendRequest(method,url,callback,query,sync,data){
        if(method == 'get'){
            if(sync){
                return sfw.Http.syncGet(url,callback,query);
            } else {
                return sfw.Http.get(url,callback,query);
            }
        } else if(method == 'post'){
            if(sync){
                return sfw.Http.syncPost(url,callback,query,data);
            } else {
                return sfw.Http.post(url,callback,query,data);
            }
        } else if(method == 'put'){
            if(sync){
                return sfw.Http.syncPut(url,callback,query,data);
            } else {
                return sfw.Http.put(url,callback,query,data);
            }
        }
    }

    return {
        // @GET		@Path("/")
        // public CommunityResponse GetCommunity()
        getCommunityHome : function(handler,request){
            return sendRequest('get',getUrl(0),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },{
                pn:request.pagePosition ? request.pagePosition : 1,
                ps:request.pageSize ? request.pageSize : 10,
                Key:request.key ? request.key : "" ,
                CommunityType:request.type
            },request.sync);
            function toViewModel(data){
                var view = {};
                view.code = data.ResponseCode;
                view.message = data.ResponseMessage;
                view.data = [];
                var index = 0;
                if(data.CommunityItems){
                    for(var i=0;i<data.CommunityItems.length;i++){
                        if(data.CommunityItems[i] != null) {
                            index = view.data.length;
                            view.data[index] = {};
                            view.data[index].CommunityID = data.CommunityItems[i].CommunityID;
                            view.data[index].CommunityName = data.CommunityItems[i].CommunityName;
                            view.data[index].imgUrl = data.CommunityItems[i].CommunityLogoPathUrl;
                            view.data[index].CommunityStatus = data.CommunityItems[i].CommunityStatus;
                            view.data[index].CommunityType = data.CommunityItems[i].CommunityType;
                            view.data[index].membersCount = data.CommunityItems[i].CommunityMembersCount;
                            //view.data[index].count = data.CommunityItems[i].CommunityMembersCount;
                        }
                    }
                }
                return view;
            }
        },
        // @GET		@Path("/{communityId}")
        // public CommunityDetailResponse GetCommunityProfileDetails()
        getCommunityDetail:function(handler,request){
            return sendRequest('get',getUrl(1,request.communityId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },null,request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/{communityId}/Membership")
        // public CommunityMembershipResponse GetCommunityUserDetails()
        getCommunityMemberShip:function(handler,request){
            return sendRequest('get',getUrl(2,request.communityId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },{
                ps : request.pageSize,
                sinceid : request.pagePosition,
                membertype : request.type
            },request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @POST		@Path("/Membership")
        // public BasicResponse PostJoinLeaveStatus(MembershipRequest request)
        postMemberShip:function(handler,request){
            return sendRequest('post',getUrl(3),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },{
                communityId : request.communityId,
                actionType : request.action
            },request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @PUT		@Path("/Membership")
        // public BasicResponse PutApproveRejectRequest(PutMembershipRequest request)
        putMemberShip:function(handler,request){
            return sendRequest('put',getUrl(3),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },{
                communityId : request.communityId,
                pendingUser : request.user,
                ActionStatus : request.action,
                notificationId : request.notificationId
            },request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @POST		@Path("/Subscribe")
        // public BasicResponse PostCommunitySubscribe(PostSubscribeRequest request)
        postSubscribe:function(handler,request){
            return sendRequest('post',getUrl(4),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },{
                CommunityId : request.communityId,
                ActionType : request.action
            },request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/Search")
        // public CommunitySearchResponse GetSearchedCommunity()
        search:function(handler,request){
            return sendRequest('get',getUrl(5),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },{
                pn : request.pagePosition,
                ps : request.pageSize,
                Key : request.key,
                CommunityType : request.type
            },request.sync);
            function toViewModel(data){
                var view = {};
                view.code = data.ResponseCode;
                view.message = data.ResponseMessage;
                view.data = [];
                var index = 0;
                if(data.CommunityItems){
                    for(var i=0;i<data.CommunityItems.length;i++){
                        if(data.CommunityItems[i] != null) {
                            index = view.data.length;
                            view.data[index] = {};
                            view.data[index].CommunityID = data.CommunityItems[i].CommunityID;
                            view.data[index].CommunityName = data.CommunityItems[i].CommunityName;
                            view.data[index].imgUrl = data.CommunityItems[i].CommunityLogoPathUrl;
                            view.data[index].CommunityStatus = data.CommunityItems[i].CommunityStatus;
                            view.data[index].CommunityType = data.CommunityItems[i].CommunityType;
                            view.data[index].membersCount = data.CommunityItems[i].CommunityMembersCount;
                            //view.data[index].count = data.CommunityItems[i].CommunityMembersCount;
                        }
                    }
                }
                return view;
            }
        },
        // @GET		@Path("/{notificationId}/Expert")
        // public ExportResponse GetExpertDetails(@PathParam("notificationId") String notificationId)
        getExport:function(handler,request){
            return sendRequest('get',getUrl(6,request.notificationId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },{
                rowno : request.pagePosition,
                ps : request.pageSize,
                NotificationType : request.notificationType,
                TargetId : request.targetId
            },request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @POST		@Path("/Nominate")
        // public BasicResponse UpdateExpertDetails(NominateRequest request)
        nominate:function(handler,request){
            return sendRequest('post',getUrl(7),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },{
                NotificationId : request.notificationId,
                Cid : request.targetId,
                ExpertsIds : request.exports,
                Tags : request.tags
            },request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/CommunityStats")
        // public CommunityStatsResponse GetCommunityStats()
        getStat:function(handler,request){
            return sendRequest('get',getUrl(8),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },{
                Cid : request.communityId
            },request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @POST		@Path("/New")
        // public CommunityCreatResponse PostCommunity(CommunityCreatRequest request)
        create:function(handler,request){
            var domain = {
                CommunityName : request.name,
                CommunityDescription : request.description,
                StartDate : request.start,
                EndDate : request.end,
                CommunityNickName : request.nickname,
                CommunityType : request.type,
                CommunityLogo : request.logo,
                CommunityTags : request.tags,
                CommunityApps : request.apps,
                Members : request.memebers,
                Moderators : request.managers
            };
            return sendRequest('post',getUrl(9),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },domain,request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/{Name}/Exist")
        // public ExistResponse GetNameAvailability(@PathParam("Name") String name)
        exist:function(handler,request){
            return sendRequest('get',getUrl(10,request.name),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },{
                type : request.type
            },request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/Types")
        // public CommunityTypeResponse GetCommunityTypes()
        getTypes:function(handler,request){
            return sendRequest('get',getUrl(11),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },null,request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @PUT		@Path("/{communityId}/Membership")
        // public BasicResponse PutAddOrRemoveUsers(@PathParam("communityId") String communityId,List<MemberRequest> request)
        postCommunityMemberShip:function(handler,request){
            var domain = [];
            for(var i=0;i<request.users.length;i++){
                domain[i] = {};
                domain[i].UserID = request.users[i].user;
                domain[i].Action = request.users[i].action;
                domain[i].IsModerator = request.users[i].isManager;
            }
            return sendRequest('put',getUrl(2,request.communityId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },domain,request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @PUT		@Path("/{communityId}/Edit")
        // public BasicResponse PutEditCommunity(@PathParam("communityId") String communityId,CommunityEditRequest request)
        editCommunity:function(handler,request){
            var domain = {};
            domain.CommunityStatus = request.status;
            domain.CommunityName = request.name;
            domain.CommunityDescription = request.description;
            domain.StartDate = request.startDate;
            domain.EndDate = request.endDate;
            domain.CommunityNickName = request.nickname;
            domain.CommunityType = request.type;
            domain.CommunityLogo = request.logo;
            domain.CommunityTags = request.tags;
            domain.CommunityApps = request.apps;
            domain.CommmunityMembers = [];
            for(var i=0;i<request.members.length;i++){
                domain.CommmunityMembers[i] = {};
                domain.CommmunityMembers[i].UserID = request.members[i].user;
                domain.CommmunityMembers[i].Action = request.members[i].action;
                domain.CommmunityMembers[i].IsModerator = request.members[i].isManager;
            }
            domain.CommmunityModerators = [];
            for(var i=0;i<request.managers.length;i++){
                domain.CommmunityModerators[i] = {};
                domain.CommmunityModerators[i].UserID = request.managers[i].user;
                domain.CommmunityModerators[i].Action = request.managers[i].action;
                domain.CommmunityModerators[i].IsModerator = request.managers[i].isManager;
            }
            return sendRequest('put',getUrl(12,request.communityId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },domain,request.sync);
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/Types")
        // public CommunityTypeResponse GetCommunityTypes()
        getExports:function(handler,request){
            return sendRequest('get',getUrl(13,request.notificationId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data));
                    }
                }
            },{
                NotificationType		: 	request.notificationType,
                TargetId				:	request.targetId,
                ps						: 	request.pageSize,
                rowno					:	request.pagePosition
            },request.sync);
            function toViewModel(data){
                return data;
            }
        }
    }
})();

//@Path("/Tag")
Workport.ContactAPI = (function(){

    var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'Contact';

    var urls = ["","/Self","/New"];

    function getUrl(/*index, replace1, replace2, ...*/) {
        var index, i, loops, r;
        loops = arguments.length;
        if (loops > 0) {
            index = arguments[0];
            r = root + urls[index];
            for (i = 1; i < loops; i++)
                r = r.replace("{"+i+"}", arguments[i]);
        }
        return r;
    }

    function sendGetRequest(url,callback,query,sync){
        if(sync){
            return sfw.Http.syncGet(url,callback,query);
        } else {
            return sfw.Http.get(url,callback,query);
        }
    }

    return {
        // @GET		@Path("/")
        // Contact?userIdkey=CA228&userNamekey=CA228&locationKey=&positionKey=&action=3&ps=20&offset=0
        // public ContactResponse GetAllContacts()
        searchContact:function(handler,request){
            var domain = {

                ps : request.pageSize,
                offset : request.offset
            }
            if(request.userId || request.userName || request.location || request.position){
                domain.userIdkey = request.userId;
                domain.userNamekey = request.userName;
                domain.locationKey = request.location;
                domain.positionKey = request.position;
                domain.action = request.action;
            }
            return sendGetRequest(getUrl(0),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            }, domain ,request.sync);
        },
        // @GET		@Path("/Self")
        // public ContactResponse GetMyContacts()
        getSelfContact:function(handler,request){
            var domain = {
                filter:request.filter,
                ps:request.pageSize,
                offset:request.offset
            };
            if(request.action || request.userName){
                domain.action = request.action;
                domain.userNamekey = request.userName;
            }
            if(request.userId){
                domain.userIdkey = request.userId;
            }
            if(request.position){
                domain.positionKey = request.position;
            }
            return sendGetRequest(getUrl(1),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data,xhr);
                    }
                }
            },domain,request.sync);
        },
        // @POST		@Path("/New")
        // public BasicResponse NewContacts()
        addContact:function(handler,request){
            return sfw.Http.post(getUrl(2),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },null,{
                IDs:request.ids,
                action:request.action
            });
        }
    }
})();

// @Path("/Document")
Workport.DocumentAPI = (function(){

    var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'Document/';

    var urls = ["Self", "MashUp", "{1}", "search", "{1}/Community", "{1}", "DiscardCheckOut/{1}", "{1}/Version",
        "Copy", "Restore", "CopyTo" ];

    function getUrl(/*index, replace1, replace2, ...*/) {
        var index, i, loops, r;
        loops = arguments.length;
        if (loops > 0) {
            index = arguments[0];
            r = root + urls[index];
            for (i = 1; i < loops; i++)
                r = r.replace("{"+i+"}", arguments[i]);
        }
        return r;
    }

    return {
        // @GET		@Path("/Self")
        // public SelfDocumentResponse GetMyDocuments()
        getSelf:function(handler,request){
            var domain = {
                order:request.order,
                ps:request.pageSize != undefined?request.pageSize:10,
                filter:request.filter?request.filter:'Time',
                offset:request.offset?request.offset:"''"
            };
            if(request.key){
                domain.key = request.key;
            }
            return sfw.Http.get(getUrl(0),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },domain);
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/MashUp")
        // public CommunityDocumentResponse  GetAllDocuments()
        getAll:function(handler,request){
            return sfw.Http.get(getUrl(1),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                order:request.order,
                ps:request.pageSize!= undefined?request.pageSize:10,
                sinceid:request.sinceid?request.sinceid:'0',
                filter:request.filter?request.filter:'Time',
                key:request.key?request.key:""
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/{DocumentId}")
        // public DocumentResponse GetDocumentDetails(@PathParam("DocumentId") String documentId)
        getDetail:function(handler,request){
            return sfw.Http.get(getUrl(2,request.documentId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                ntype:request.type,
                tid:request.targetId
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/search")
        // public SearchDocumentResponse  GetDocumentsSearch()
        search:function(handler,request){
            var domain = {
                key:request.key,
                entity:request.entity,
                ps:request.pageSize!= undefined?request.pageSize:10
            };
            if(request.offset){
                domain.offset = request.offset;
            }
            return sfw.Http.get(getUrl(3),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },domain);
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/{communityId}/Community")
        // public SelfDocumentResponse GetCommunityDocs(@PathParam("communityId") String communityId)
        getCommunity:function(handler,request){
            var domain = {
                ps:request.pageSize!= undefined?request.pageSize:10,
                offset:request.offset?request.offset:""
            };
            if(request.filter && request.order){
                domain.filter = request.filter;
                domain.order = request.order;
            }
            return sfw.Http.get(getUrl(4,request.communityId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },domain );
            function toViewModel(data){
                return data;
            }
        },
        // @PUT		@Path("/{NotificationId}")
        // public BasicResponse CheckIn(@PathParam("NotificationId") String notificationId,CheckInRequest request)
        checkin:function(handler,request){
            return sfw.Http.put(getUrl(5,request.notificationId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NotificationType : request.notificationType,
                DocumentId       : request.documentId,
                TargetId         : request.targetId,
                Version          : request.version,
                Comments		 : request.comments ? request.comments : "''",
                DocumentByte     : request.documentContent
            });
            function toViewModel(data){
                return data;
            }
        },
        // @POST		@Path("/{NotificationId}")
        // public BasicResponse CheckOut(@PathParam("NotificationId") String notificationId,CheckOutRequest request)
        checkout:function(handler,request){
            return sfw.Http.post(getUrl(5,request.notificationId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NotificationType : request.notificationType,
                DocumentId       : request.documentId,
                TargetId         : request.targetId
            });
            function toViewModel(data){
                return data;
            }
        },
        // @POST		@Path("/DiscardCheckOut/{NotificationId}")
        // public BasicResponse DiscardCheckOut(@PathParam("NotificationId") String notificationId,CheckOutRequest request)
        discard:function(handler,request){
            return sfw.Http.post(getUrl(6,request.notificationId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NotificationType : request.notificationType,
                DocumentId       : request.documentId,
                TargetId         : request.targetId
            });
            function toViewModel(data){
                return data;
            }
        },
        // @GET		@Path("/{DocumentId}/Version")
        // public DocumentVersionResponse GetVersionDetails(@PathParam("DocumentId") String documentId)
        getVersion:function(handler,request){
            return sfw.Http.get(getUrl(7,request.documentId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                ntype	: request.type,
                tid	 	: request.targetId
            });
            function toViewModel(data){
                return data;
            }
        },
        // @POST		@Path("/Copy")
        // public BasicResponse PostCopyDocument(DocumentCopyRequest request)
        copy:function(handler,request){
            return sfw.Http.post(getUrl(8),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                TargetId		:	request.targetId,
                Tags			: 	request.tags ? request.tags : "''",
                EntityID		: 	request.entityId,
                EntityType		:	request.entityType,
                FromCommunityId	:	request.communityId,
                AttachContents	:	{
                    AttachmentName  : request.attachmentName,
                    AttachmentType  : request.attachmentType,
                    Attachmentbytes : request.attachmentContent
                }
            });
            function toViewModel(data){
                return data;
            }
        },
        // @POST		@Path("/Restore")
        // public BasicResponse PostDocumentRestore(DocumentRestoreRequest request)
        restore:function(handler,request){
            return sfw.Http.post(getUrl(9),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                DocumentId : request.documentId,
                VersionNo  : request.version,
                ntype      : request.type,
                tid        : request.targetId
            });
            function toViewModel(data){
                return data;
            }
        },
        // @POST		@Path("/CopyTo")
        // public BasicResponse PostCopyDocument(DocumentCopyRequest request)
        copyto:function(handler,request){
            return sfw.Http.post(getUrl(10),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{},{
                SourceId		:	request.src,
                DestinationId	: 	request.dest,
                DocumentId		: 	request.documentId,
                NotificationType:	request.type
            });
            function toViewModel(data){
                return data;
            }
        }
    }
})();

//@Path("/Tag")
Workport.ExpertsAPI = (function(){

    var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/');

    var urls = ["Experts"];

    function getUrl(/*index, replace1, replace2, ...*/) {
        var index, i, loops, r;
        loops = arguments.length;
        if (loops > 0) {
            index = arguments[0];
            r = root + urls[index];
            for (i = 1; i < loops; i++)
                r = r.replace("{"+i+"}", arguments[i]);
        }
        return r;
    }

    function sendGetRequest(url,callback,query,sync){
        if(sync){
            return sfw.Http.syncGet(url,callback,query);
        } else {
            return sfw.Http.get(url,callback,query);
        }
    }

    return {
        // @GET	@Path("/Experts")
        // public TagResponse GetAllExperts()
        getExperts:function(handler,request){
            return sendGetRequest(getUrl(0),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                tags:request.tag,
                ps:request.ps,
                pn:request.pn
            },request.sync);
        }
    }
})();

// @Path("/Stream")
Workport.StreamAPI = (function(){
    var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'Stream';

    var urls = ["/Basic", "", "/{1}", "/ShareGeneric", "/Share", "/Update", "/UpdateGeneric", "/Filter", "/Entities", "/Comment",
        "/{1}/Comment", "/Like", "/{1}/Like", "/Bookmark", "/Subscribe", "/Delete", "/{1}/Export", "/Search", "/Community" , "/UserSubscribe",
        "/TaggingUser", "/Community/{1}" , "/Sticky", "/MailSubscribe", "/CommentGeneric","/sendmail","/AtMentionUsers"];

    function getUrl(/*index, replace1, replace2, ...*/) {
        var index, i, loops, r;
        loops = arguments.length;
        if (loops > 0) {
            index = arguments[0];
            r = root + urls[index];
            for (i = 1; i < loops; i++)
                r = r.replace("{"+i+"}", arguments[i]);
        }
        return r;
    }

    function sendRequest(method,url,callback,query,sync,data){
        if(method == 'get'){
            if(sync){
                return sfw.Http.syncGet(url,callback,query);
            } else {
                return sfw.Http.get(url,callback,query);
            }
        } else if(method == 'post'){
            if(sync){
                return sfw.Http.syncPost(url,callback,query,data);
            } else {
                return sfw.Http.post(url,callback,query,data);
            }
        } else if(method == 'put'){
            if(sync){
                return sfw.Http.syncPut(url,callback,query,data);
            } else {
                return sfw.Http.put(url,callback,query,data);
            }
        }
    }

    return {
        // @GET		@Path("/Basic")
        // public StreamResponse GetSmartstream()
        getBasicStream:function(handler,request){
            return sendRequest('get',getUrl(0),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler,xhr)){
                        handler(data,xhr);
                    }
                }
            },{
                ps 		: 	request.pageSize,
                latest	:	request.latest,
                offset	:	request.offset ? request.offset : "",
                filter	:	request.filter ? request.filter : "0"
            },request.sync);
        },
        // @GET		@Path("/Search")
        // public StreamResponse searchStream()
        searchStream:function(handler,request){
            var domain = {
                key     :   request.key,
                ps 		: 	request.pageSize,
                offset	:	request.offset,
                tid		:	request.targetId
            };
            if(request.type){
                domain.type = request.type;
            }
            if(request.ispersonal){
                domain.ispersonal = request.ispersonal;
            }
            return sendRequest('get',getUrl(17),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },domain,request.sync);
        },
        // @GET		@Path("/")
        // public StreamDefaultResponse GetDefaultStream()
        getDefaultStream:function(handler,request){
            return sendRequest('get',getUrl(1),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler,xhr)){
                        handler(data,xhr);
                    }
                }
            },{
                ps 		: 	request.pageSize,
                latest	:	request.latest,
                offset	:	request.offset ? request.offset : "",
                filter	:	request.filter ? request.filter : "0",
                order   :   request.order
            },request.sync);
        },
        // @GET        @Path("/")
        // public StreamDefaultResponse GetDefaultStream()
        getConversationStream:function(handler,request){
            var domain = {
                tid         :     request.tid,
                ispersonal    :    request.ispersonal
            };
            if(request.pageSize || request.offset || request.latest){
                domain.ps        =     request.pageSize;
                domain.latest    =    request.latest;
                domain.offset    =    request.offset;
            }
            if(request.filter || request.order){
                domain.filter = request.filter;
                domain.order = request.order;
            }
            return sendRequest('get',getUrl(1,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },domain,request.sync);
        },
        // @GET	@Path("/{NotificationID}")
        // public StreamDefaultResponse GetSmartNotification(@PathParam("NotificationID") String nofificationID)
        getStreamByNotify:function(handler,request){
            return sendRequest('get',getUrl(2,request.notificationId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                ntype	:	request.type,
                tid		:	request.targetId,
                source  :   request.source
            },request.sync);
        },
        // @GET	@Path("/{NotificationID}")
        // public StreamDefaultResponse GetSmartNotification(@PathParam("NotificationID") String nofificationID)
        getStreamByTarget:function(handler,request){
            return sendRequest('get',getUrl(2,request.notificationId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                tid			:	request.targetId,
                ispersonal	:	request.isPeronal
            },request.sync);
        },
        // @POST	@Path("/ShareGeneric")
        // public ShareResponse SharePost(ShareGenericPostRequest request)
        shareGeneric:function(handler,request){
            var domain = {};
            domain.TargetId = request.targetId;
            domain.EntityId = request.entityId;
            domain.NotificationText = request.text;
            domain.NotificationType = request.type;
            domain.Featured = request.featured ? request.featured :"''";
            domain.SubEntity = request.subEntity ? request.subEntity :"''";
            domain.Tags = request.tags ? request.tags :"''";
            domain.NotificationTitle = request.title ? request.title :"''";
            domain.hyperlinkURL = request.url ? request.url :"''";
            if(request.attachments){
                domain.AttachContents = [];
                for(var i=0;i<request.attachments.length;i++){
                    domain.AttachContents[i] = {};
                    domain.AttachContents[i].AttachmentName = request.attachments[i].name;
                    domain.AttachContents[i].Attachmentbytes = request.attachments[i].content;
                    domain.AttachContents[i].AttachmentType = request.attachments[i].type ? request.attachments[i].type : "''";
                }
            }
            if(request.images){
                domain.ImageContents = [];
                for(var i=0;i<request.images.length;i++){
                    domain.ImageContents[i] = {};
                    domain.ImageContents[i].AttachmentName = request.images[i].name;
                    domain.ImageContents[i].Attachmentbytes = request.images[i].content;
                    domain.ImageContents[i].AttachmentType = request.images[i].type ? request.images[i].type : "''";
                }
            }
            return sendRequest('post',getUrl(3),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },request,request.sync);
        },
        // @POST @Path("/Share")
        // public ShareResponse SharePost(SharePostRequest request)
        share:function(handler,request){
            return sendRequest('post',getUrl(4),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },request,request.sync/*{
             TargetId : request.targetId,
             EntityId : request.entityId,
             NotificationText : request.text,
             NotificationType : request.type,
             SubEntity : request.subEntity ? request.subEntity :"''",
             NotificationTitle : request.title ? request.title :"''",
             Tags : request.tags ? request.tags :"''"
             }*/);
        },
        // @PUT	@Path("/Update")
        // public BasicResponse PutUpdatePost(UpdateRequest request)
        putUpdate:function(handler,request){
            return sendRequest('put',getUrl(5),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                TargetId  : request.targetId,
                NotificationId  : request.Id,
                NotificationType  : request.type,
                NotificationText  : request.text,
                status  : request.status ? request.status : "''",
                AdditionalData  : request.additionalData ? request.additionalData : "''",
                Tags  : request.tags ? request.tags : "''",
                NotificationTitle  : request.title ? request.title : "''",
                BroadcastTo  : request.broadcast ? request.broadcast : "''"
            },request.sync);
        },
        // @PUT	@Path("/UpdateGeneric")
        // public BasicResponse PutUpdatePost(GenericUpdateRequest request)
        putGenericUpdate:function(handler,request){
            var domain = {};
            domain.TargetId  = request.targetId;
            domain.NotificationId  = request.id;
            domain.NotificationType  = request.type;
            domain.NotificationText  = request.text;
            domain.EntityId  = request.entityId;
            domain.hyperlinkURL  = request.url;
            domain.status  = request.status;
            domain.AdditionalData  = request.additionalData;
            domain.Tags  = request.tags;
            domain.NotificationTitle  = request.title;
            domain.BroadcastTo  = request.broadcast;
            domain.SubEntity  = request.subEntity;
            if(request.attachments){
                domain.AttachContents = [];
                for(var i=0;i<request.attachments.length;i++){
                    domain.AttachContents[i] = {};
                    domain.AttachContents[i].AttachmentName = request.attachments[i].AttachmentName;
                    domain.AttachContents[i].Attachmentbytes = request.attachments[i].Attachmentbytes;
                    if(request.attachments[i].AttachmentType){
                        domain.AttachContents[i].AttachmentType = request.attachments[i].AttachmentType;
                    }
                }
            }
            if(request.images){
                domain.ImageContents = [];
                for(var i=0;i<request.images.length;i++){
                    domain.ImageContents[i] = {};
                    domain.ImageContents[i].AttachmentName = request.images[i].AttachmentName;
                    domain.ImageContents[i].Attachmentbytes = request.images[i].Attachmentbytes;
                    if(request.images[i].AttachmentType){
                        domain.ImageContents[i].AttachmentType = request.images[i].AttachmentType;
                    }
                }
            }
            return sendRequest('put',getUrl(6),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },domain,request.sync);
        },
        // @GET	@Path("/Filter")
        // public List<Filter> FilterType()
        getFilter:function(handler,request){
            return sendRequest('get',getUrl(7),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },null,request ? request.sync : null);
        },
        // @GET	@Path("/Entities")
        // public List<Entity> GetEntityTypes()
        getEntities:function(handler,request){
            return sendRequest('get',getUrl(8),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },null,request ? request.sync : null);
        },
        // @POST	@Path("/Comment")
        // public BasicResponse PostComment(PostCommentRequest request)
        postComment:function(handler,request){
            console.log(request);
            /*return sendRequest('post',getUrl(9),function(xhr,data){
             if (!sfw.Http.handleError(xhr, data)) {
             if(jQuery.isFunction(handler)){
             handler(data, xhr);
             }
             }
             },{
             NotificationId : request.id,
             NotificationType : request.type,
             CommentText : request.text,
             ToID : request.targetId
             },request.sync);*/
            return Workport.StreamAPI.postCommentGeneric(handler,{
                NotificationId : request.id,
                NotificationFromId : request.fromId,
                NotificationType : request.type,
                CommentText : request.text,
                ToID : request.targetId,
                AtMentionedUsers : request.AtMentionedUsers,
                sync : request.sync
            });
        },
        // @GET	@Path("/{NotificationID}/Comment")
        // public CommentResponse FetchComment(@PathParam("NotificationID") String nofificationID)
        getCommentByNotify:function(handler,request){
            return sendRequest('get',getUrl(10,request.id),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                tid		:	request.targetId,
                ps		:	request.pageSize,
                offset	:	request.offset,
                ntype	:	request.type
            },request.sync);
        },
        // @POST	@Path("/Like")
        // public BasicResponse PostLike(PutLikeRequest request)
        postLike:function(handler,request){
            return sendRequest('post',getUrl(11),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NotificationId : request.id,
                NotificationType : request.type,
                NotificationFromID : request.fromId,
                TargetId : request.targetId,
                CommentedByID : request.commentedBy,
                CommentId : request.commentId
            },request.sync);
        },
        // @GET	@Path("/{NotificationID}/Like")
        // public List<LikeDetailResponse> GetLikedUsers(@PathParam("NotificationID") String nofificationID)
        getLikeByNotify:function(handler,request){
            return sendRequest('get',getUrl(12,request.targetId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                ps	:	request.pageSize,
                pn	:	request.pageNumber
            },request.sync);
        },
        // @GET	@Path("/{NotificationID}/Like")
        // public List<LikeDetailResponse> GetLikedUsers(@PathParam("NotificationID") String nofificationID)
        getLikeDetail:function(handler,request){
            var url = "Stream/"+request.id+"/Like";
            return sendRequest('get',getUrl(12,request.targetId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },null,request.sync);
        },
        // @POST	@Path("/Bookmark")
        // public BasicResponse Bookmark(BookmarkRequest request)
        bookmark:function(handler,request){
            return sendRequest('post',getUrl(13),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NotificationId : request.id,
                NotificationType : request.type,
                ActionType : request.action,
                CommunityId : request.communityId
            },request.sync);
        },
        // @POST	@Path("/Subscribe")
        // public BasicResponse PostUpdateSubscription(SubscribeRequest request)
        subscribe:function(handler,request){
            return sendRequest('post',getUrl(14),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NotificationID : request.id,
                ActionType : request.action,
                CommunityId : request.communityId
            },request.sync);
        },
        // @POST	@Path("/UserSubscribe")
        // public BasicResponse PostUpdateSubscription(SubscribeRequest request)
        userSubscribe:function(handler,request){
            return sendRequest('post',getUrl(19),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NotificationID : request.id,
                ActionType : request.action,
                TarGetUserId : request.communityId
            },request.sync);
        },
        // @POST	@Path("/TaggingUser")
        // public BasicResponse TaggingUser(TaggingUserRequest request)
        taggingUser:function(handler,request){
            return sendRequest('post',getUrl(20),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                visitedUserId : request.userId,
                tagValue : request.tag
            },request.sync);
        },
        // @PUT	@Path("/Delete")
        // public BasicResponse Delete(DeleteRequest request)
        deleteStream:function(handler,request){
            return sendRequest('put',getUrl(15),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NotificationId : request.id,
                NotificationType : request.type,
                TargetId : request.targetId
            },request.sync);
        },
        // @POST	@Path("/{notifyId}/Expert")
        // public BasicResponse UpdateExpertDetails(@PathParam("notifyId") String notifyId,ExpertRequest request)
        exportStream:function(handler,request){
            return sendRequest('post',getUrl(16,request.id),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NotificationId : request.id,
                NotificationType : request.type,
                TargetId : request.targetId,
                ExpertsIds : request.exportId
            },request.sync);
        },
        // add commont with attach,this will put UpdateGeneric and post Comment
        // @PUT		@Path("/UpdateGeneric")
        // @POST	@Path("/Comment")
        addCommentWithAttachOld:function(handler,request){
            var r = [];
            var domain = {};
            domain.TargetId  = request.targetId4Update;
            domain.NotificationId  = request.id;
            domain.NotificationType  = request.type;
            domain.NotificationText  = request.text4Update;
            domain.EntityId  = request.entityId;
            domain.hyperlinkURL  = request.url;
            domain.status  = request.status;
            domain.AdditionalData  = request.additionalData;
            domain.Tags  = request.tags;
            domain.NotificationTitle  = request.title;
            domain.BroadcastTo  = request.broadcast;
            domain.SubEntity  = request.subEntity;
            if(request.attachments){
                domain.AttachContents = [];

                for(var i=0;i<request.attachments.length;i++){
                    domain.AttachContents[i] = {};
                    domain.AttachContents[i].AttachmentName = request.attachments[i].AttachmentName;
                    domain.AttachContents[i].Attachmentbytes = request.attachments[i].Attachmentbytes;
                    if(request.attachments[i].AttachmentType){
                        domain.AttachContents[i].AttachmentType = request.attachments[i].AttachmentType;
                    }
                }
            }
            if(request.images){
                domain.ImageContents = [];
                for(var i=0;i<request.images.length;i++){
                    domain.ImageContents[i] = {};
                    domain.ImageContents[i].AttachmentName = request.images[i].AttachmentName;
                    domain.ImageContents[i].Attachmentbytes = request.images[i].Attachmentbytes;
                    if(request.images[i].AttachmentType){
                        domain.ImageContents[i].AttachmentType = request.images[i].AttachmentType;
                    }
                }
            }
            r[0] = {
                url 	:	getUrl(6),
                method 	:	"PUT",
                data	:	domain
            };
            r[1] = {
                url 	:	getUrl(9),
                method 	:	"POST",
                data	:	{
                    NotificationId : request.id,
                    NotificationType : request.type,
                    CommentText : request.text4Comment,
                    ToID : request.targetId4Comment
                }
            };
            sfw.Http.batch(r,handler);
        },
        // add commont with attach,this will put UpdateGeneric and post Comment
        // @PUT		@Path("/UpdateGeneric")
        // @POST	@Path("/Comment")
        addCommentWithAttach:function(handler,request){
            var domain = {};
            domain.NotificationId  = request.id;
            domain.NotificationType  = request.type;
            domain.NotificationFromId = request.fromId;
            domain.CommentText  = request.text4Comment;
            domain.ToID  = request.targetId4Comment;
            domain.AtMentionedUsers  = request.AtMentionedUsers;
            if(request.attachments){
                domain.AttachContents = [];
                for(var i=0;i<request.attachments.length;i++){
                    domain.AttachContents[i] = {};
                    domain.AttachContents[i].AttachmentName = request.attachments[i].AttachmentName;
                    domain.AttachContents[i].Attachmentbytes = request.attachments[i].Attachmentbytes;
                    if(request.attachments[i].AttachmentType){
                        domain.AttachContents[i].AttachmentType = request.attachments[i].AttachmentType;
                    }
                }
            }
            if(request.images){
                domain.ImageContents = [];
                for(var i=0;i<request.images.length;i++){
                    domain.ImageContents[i] = {};
                    domain.ImageContents[i].AttachmentName = request.images[i].AttachmentName;
                    domain.ImageContents[i].Attachmentbytes = request.images[i].Attachmentbytes;
                    if(request.images[i].AttachmentType){
                        domain.ImageContents[i].AttachmentType = request.images[i].AttachmentType;
                    }
                }
            }
            domain.sync = request.sync
            return Workport.StreamAPI.postCommentGeneric(handler,domain);
        },
        // get commont with like,this will get like and get comment
        // @GET		@Path("/{id}/Like")
        // @GET	@Path("/{id}/Comment")
        getCommentAndLike:function(handler,request){
            var r = [];
            r[0] = {
                url 	:	getUrl(10,request.id),//{1}/Comment
                method 	:	"GET",
                query	:	{
                    tid		: request.targetId,
                    ps		: request.pageSize4Comment,
                    offset	: request.offset,
                    ntype	: request.type
                }
            };
            r[1] = {
                url 	:	getUrl(12,request.id),//{1}/Like
                method 	:	"GET",
                query	:	{
                    ps:request.pageSize4Like,
                    pn:request.PageNumber
                }
            };
            sfw.Http.batch(r,handler);
        },
        ///////////////////////////////////////////////////////  For Community
        // @GET		@Path("/Community/{communityid}")
        // public CommunityNotificationResponse GetCommunityStream(@PathParam("communityid") String communityid)
        getCommunityDetail:function(handler,request){
            return sendRequest('get',getUrl(21,request.communityId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data), xhr);
                    }
                }
            },{
                ps:request.pageSize,
                pp:request.pagePosition,
                order:request.order,
                filter:request.filter
            },request.sync);
            function toViewModel(data){
                if(data && data.Notifications){
                    for(var i=0;i<data.Notifications.length;i++){
                        data.Notifications[i].Attachments = data.Notifications[i].Attachment;
                        data.Notifications[i].Images = data.Notifications[i].Image;
                    }
                }
                return data;
            }
        },
        // @GET	@Path("/Community")
        // public BasicResponse GetCommunityStreamPreview()
        getCommunityPreview:function(handler,request){
            return sendRequest('get',getUrl(18),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(toViewModel(data), xhr);
                    }
                }
            },{
                ps:request.pageSize,
                pp:request.pagePosition,
                order:request.order,
                ctype:request.type
            },request.sync);
            function toViewModel(data){
                var view;
                if(data){
                    view = {};
                    view.code = data.ResponseCode;
                    view.message = data.ResponseMessage;
                    view.data = [];
                    if(data!=undefined){
                        for(var i=0;data.NotificationPreviews && i < data.NotificationPreviews.length;i++){
                            view.data[i] = {};
                            view.data[i].id = data.NotificationPreviews[i].CommunityId;
                            view.data[i].icon = data.NotificationPreviews[i].CommunityImageUrl;
                            view.data[i].title = data.NotificationPreviews[i].CommunityName;
                            view.data[i].tip = 0;
                            view.data[i].tags = [];
                            for(var j=0;data.NotificationPreviews[i].CommunityTags && j<data.NotificationPreviews[i].CommunityTags.length;j++){
                                view.data[i].tags[j] = data.NotificationPreviews[i].CommunityTags[j];
                            }
                            view.data[i].notes = [];
                            for(var j=0;data.NotificationPreviews[i].ShortNotifications && j<data.NotificationPreviews[i].ShortNotifications.length;j++){
                                view.data[i].notes[j] = {};
                                view.data[i].notes[j].id = data.NotificationPreviews[i].ShortNotifications[j].NotificationId;
                                view.data[i].notes[j].fromId = data.NotificationPreviews[i].ShortNotifications[j].FromId;
                                view.data[i].notes[j].pic = data.NotificationPreviews[i].ShortNotifications[j].FromImageUrl;
                                view.data[i].notes[j].title = data.NotificationPreviews[i].ShortNotifications[j].NotificationTitle;
                                view.data[i].notes[j].desc = data.NotificationPreviews[i].ShortNotifications[j].NotificationText;
                                view.data[i].notes[j].passed = Workport.utils.calDays(data.NotificationPreviews[i].ShortNotifications[j].LastModifiedDate,data.NotificationPreviews[i].ServerDate);
                            }
                            if(i == data.NotificationPreviews.length - 1){
                                view.page = data.NotificationPreviews[i].PagePosition;
                            }
                        }
                    }
                }
                return view;
            }
        },
        // @POST		@Path("/Sticky")
        // public BasicResponse PutStickyDetails(StickyRequest request)
        setSticky:function(handler,request){
            return sendRequest('post',getUrl(22),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NotificationID:request.notificationId,
                ActionType:request.action,
                CommunityId:request.communityId
            },request.sync);
        },
        // @POST		@Path("/MailSubscribe")
        // public BasicResponse MailSubscription(MailSubscriptionRequest request)
        subscriptionMail:function(handler,request){
            return sendRequest('post',getUrl(23),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NotificationID:request.notificationId,
                ActionType:request.action,
                NotificationType:request.notificationType,
                TargetID : request.targetId
            },request.sync);
        },
        // @POST        @Path("/CommentGeneric")
        // public CommentGenericResponse CommentGeneric()
        postCommentGeneric:function(handler,request){
            return sendRequest('post',getUrl(24),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data,data);
                    }
                }
            },request,request && request.sync);
        },
        // @POST        @Path("/sendmail")
        // public BasicResponse sendUserMail(SendMailRequest request)
        sendMail:function(handler,request){
            return sendRequest('post',getUrl(25,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },request,request && request.sync);
        },
        // @GET        @Path("/AtMentionUsers")
        // public MentionUserResponse GetAtMentionUsers()
        getMentionUsers:function(handler,request){
            return sendRequest('get',getUrl(26,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                TargetID:request.targetID,
                Ntype:request.type
            },request && request.sync);
        }
    }
})();

//@Path("/Tag")
Workport.TagAPI = (function(){

    var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'Tag/';

    var urls = [""];

    function getUrl(/*index, replace1, replace2, ...*/) {
        var index, i, loops, r;
        loops = arguments.length;
        if (loops > 0) {
            index = arguments[0];
            r = root + urls[index];
            for (i = 1; i < loops; i++)
                r = r.replace("{"+i+"}", arguments[i]);
        }
        return r;
    }

    function sendGetRequest(url,callback,query,sync){
        if(sync){
            return sfw.Http.syncGet(url,callback,query);
        } else {
            return sfw.Http.get(url,callback,query);
        }
    }

    return {
        // @GET	@Path("/{key}")
        // public TagResponse GetAllTags(@PathParam("key") String tagKey)
        // getTag:function(handler,request){
        // 	return sendGetRequest(getUrl(0),function(xhr,data){
        // 		if (!sfw.Http.handleError(xhr, data)) {
        // 			if(jQuery.isFunction(handler)){
        // 				handler(data, xhr);
        // 			}
        // 		}
        // 	},{
        // 		key:request.key,
        // 		ps:request.ps,
        // 		pn:request.pn
        // 	},request.sync);
        // }
    }
})();

//@Path("/Profile")
Workport.UserAPI = (function(){
    var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'Profile/';

    var urls = ["", "Basic", "{1}", "Image", "Access", "{1}/Follow", "Network", "Auth"];

    function getUrl(/*index, replace1, replace2, ...*/) {
        var index, i, loops, r;
        loops = arguments.length;
        if (loops > 0) {
            index = arguments[0];
            r = root + urls[index];
            for (i = 1; i < loops; i++)
                r = r.replace("{"+i+"}", arguments[i]);
        }
        return r;
    }

    function sendRequest(method,url,callback,query,sync,data){
        if(method == 'get'){
            if(sync){
                return sfw.Http.syncGet(url,callback,query);
            } else {
                return sfw.Http.get(url,callback,query);
            }
        } else if(method == 'post'){
            if(sync){
                return sfw.Http.syncPost(url,callback,query,data);
            } else {
                return sfw.Http.post(url,callback,query,data);
            }
        } else if(method == 'put'){
            if(sync){
                return sfw.Http.syncPut(url,callback,query,data);
            } else {
                return sfw.Http.put(url,callback,query,data);
            }
        }
    }

    return {
        // @GET	@Path("/")
        // public UserDetailResponse UserDetails(
        getUserDetail:function(handler,sync){
            var url = "Profile";
            return sendRequest('get',getUrl(0),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data,xhr);
                    }
                }
            },null,sync);
            function toViewModel(data){
                var view = {};
                if(data.UserBasicDetailsModel){
                    view.code = data.ResponseCode;
                    view.message = data.ResponseMessage;
                    view.userImage = data.UserBasicDetailsModel[0].UserImageURL;
                    view.username = data.UserBasicDetailsModel[0].Name;
                    view.jobTitle = data.UserBasicDetailsModel[0].Department;
                    view.nickname = data.UserBasicDetailsModel[0].NickName;
                    view.userId = data.UserBasicDetailsModel[0].AccountName;
                    view.mailingAddress = data.UserBasicDetailsModel[0].Office;
                    view.emailBusiness = data.UserBasicDetailsModel[0].WorkEmail;
                    //view.emailPersonal = data.UserBasicDetailsModel[0].;
                    view.phoneBusiness = data.UserBasicDetailsModel[0].Workphone;
                    view.phoneMobile = data.UserBasicDetailsModel[0].Mobilephone;
                    //view.phoneHome = data.UserBasicDetailsModel[0].;
                    //view.leaveInfo = data.UserBasicDetailsModel[0].;
                    view.tags = data.UserBasicDetailsModel[0].Tags;
                    //view.website = data.UserBasicDetailsModel[0].BlogURL;
                    //view.resumeCV = data.UserBasicDetailsModel[0].;
                    //view.socialNetworks = data.UserBasicDetailsModel[0].;
                    view.desc = data.UserBasicDetailsModel[0].Aboutme;
                    view.notes = data.UserBasicDetailsModel[0].CurrentStatus;
                }
                return view;
            }
        },
        // @GET	@Path("/Basic")
        // public UserDetailResponse UserDetails(
        getUserBasic:function(handler){
            return sfw.Http.get(getUrl(1),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            });
            function toViewModel(data){
                var view = {};
                view.code = data.ResponseCode;
                view.message = data.ResponseMessage;
                view.accountName = data.UserBasic[0].AccountName;
                view.name = data.UserBasic[0].Name;
                view.firstName = data.UserBasic[0].FirstName;
                view.lastName = data.UserBasic[0].LastName;
                view.nickName = data.UserBasic[0].NickName;
                view.sipAddress = data.UserBasic[0].SipAddress ;
                return view;
            }
        },
        // @GET	@Path("/{userId}")
        // public UserDetailResponse UserDetails(@PathParam("userId") String userId)
        getVisitUser:function(handler,request){
            return sfw.Http.get(getUrl(2,request.userId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            });
            function toViewModel(data){
                var view = {};
                view.code = data.ResponseCode;
                view.message = data.ResponseMessage;
                view.userImage = data.UserBasicDetailsModel[0].UserImageURL;
                view.username = data.UserBasicDetailsModel[0].Name;
                view.jobTitle = data.UserBasicDetailsModel[0].Department;
                view.nickname = data.UserBasicDetailsModel[0].NickName;
                view.userId = data.UserBasicDetailsModel[0].AccountName;
                view.mailingAddress = data.UserBasicDetailsModel[0].Office;
                view.emailBusiness = data.UserBasicDetailsModel[0].WorkEmail;
                //view.emailPersonal = data.UserBasicDetailsModel[0].;
                view.phoneBusiness = data.UserBasicDetailsModel[0].Workphone;
                view.phoneMobile = data.UserBasicDetailsModel[0].Mobilephone;
                //view.phoneHome = data.UserBasicDetailsModel[0].;
                //view.leaveInfo = data.UserBasicDetailsModel[0].;
                view.tags = data.UserBasicDetailsModel[0].Tags;
                //view.website = data.UserBasicDetailsModel[0].BlogURL;
                //view.resumeCV = data.UserBasicDetailsModel[0].;
                //view.socialNetworks = data.UserBasicDetailsModel[0].;
                view.desc = data.UserBasicDetailsModel[0].Aboutme;
                view.notes = data.UserBasicDetailsModel[0].CurrentStatus;
                view.isFollow = data.UserBasicDetailsModel[0].ShowNetwork;
                return view;
            }
        },
        // @PUT	@Path("/")
        // public BasicResponse UpdateUserDetails(UserDetailRequest request)
        updateUserDetail:function(handler,request){
            var domain = {};
            domain.NickName = request.nickName;
            domain.Aboutme = request.about;
            domain.CurrentStatus = request.status;
            domain.Tags = request.tags;
            domain.Skills = request.skill;
            domain.Interests = request.interest;
            return sfw.Http.put(getUrl(0),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                NickName : request.nickName,
                Aboutme : request.about,
                CurrentStatus : request.status,
                Tags : request.tags
            });
            function toViewModel(data){
                var view = {};
                view.code = data.ResponseCode;
                view.message = data.ResponseMessage;
                return view;
            }
        },
        // @PUT	@Path("/Image")
        // public BasicResponse UpdateUserDetails(UserDetailRequest request)
        updateUserImage:function(handler,request){
            return sfw.Http.put(getUrl(3),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },request.imageBase64);
            function toViewModel(data){
                var view = {};
                view.code = data.ResponseCode;
                view.message = data.ResponseMessage;
                return view;
            }
        },
        // @GET	@Path("/Access")
        // public UserDetailResponse GetUserAccessDetails()
        // getAccessUser:function(handler,sync){
        // 	return sfw.Http.get(getUrl(4),function(xhr,data){
        // 		if (!sfw.Http.handleError(xhr, data)) {
        // 			if(jQuery.isFunction(handler)){
        // 				handler(data, xhr);
        // 			}
        // 		}
        // 	},null,sync);
        // 	function toViewModel(data){
        // 		var view = {};
        // 		view.code = data.ResponseCode;
        // 		view.message = data.ResponseMessage;
        // 		view.users = [];
        // 		if(data.UserAccessDetailsModel){
        // 			for(var i=0;i<data.UserAccessDetailsModel.length;i++){
        // 				view.users[i] = {};
        // 				view.users[i].userId = data.UserAccessDetailsModel[i].UserID;
        // 				if(data.UserAccessDetailsModel[i].ModeratorCommunities){
        // 					view.users[i].moderators = [];
        // 					for(var j=0;j<data.UserAccessDetailsModel[i].ModeratorCommunities.length;j++){
        // 						view.users[i].moderators[j] = {};
        // 						view.users[i].moderators[j].id = data.UserAccessDetailsModel[i].ModeratorCommunities[j].ID;
        // 						view.users[i].moderators[j].name = data.UserAccessDetailsModel[i].ModeratorCommunities[j].Name;
        // 					}
        // 				}
        // 				if(data.UserAccessDetailsModel[i].MemberCommunities){
        // 					view.users[i].members = [];
        // 					for(var j=0;j<data.UserAccessDetailsModel[i].MemberCommunities.length;j++){
        // 						view.users[i].members[j] = {};
        // 						view.users[i].members[j].id = data.UserAccessDetailsModel[i].MemberCommunities[j].ID;
        // 						view.users[i].members[j].name = data.UserAccessDetailsModel[i].MemberCommunities[j].Name;
        // 					}
        // 				}
        // 				if(data.UserAccessDetailsModel[i].ViewerCommunities){
        // 					view.users[i].viewers = [];
        // 					for(var j=0;j<data.UserAccessDetailsModel[i].ViewerCommunities.length;j++){
        // 						view.users[i].viewers[j] = {};
        // 						view.users[i].viewers[j].id = data.UserAccessDetailsModel[i].ViewerCommunities[j].ID;
        // 						view.users[i].viewers[j].name = data.UserAccessDetailsModel[i].ViewerCommunities[j].Name;
        // 					}
        // 				}
        // 			}
        // 		}
        // 		return view;
        // 	}
        // },
        // @PUT	@Path("/{userId}/Follow")
        // public BasicResponse FollowUnfollowUser(String userId)
        followUser:function(handler,request){
            return sfw.Http.put(getUrl(5,request.userId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },false,{
                action : request.action
            });
            function toViewModel(data){
                var view = {};
                view.code = data.ResponseCode;
                view.message = data.ResponseMessage;
                return view;
            }
        },
        // @GET @Path("/NetWork")
        // public NetWorkResponse NetWork()
        // getNetworkUser:function(handler){
        // 	return sfw.Http.get(getUrl(6),function(xhr,data){
        // 		if (!sfw.Http.handleError(xhr, data)) {
        // 			if(jQuery.isFunction(handler)){
        // 				handler(data, xhr);
        // 			}
        // 		}
        // 	});
        // 	function toViewModel(data){
        // 		var view = {};
        // 		view.code = data.ResponseCode;
        // 		view.message = data.ResponseMessage;
        // 		if(data.NetworkUsers){
        // 			view.users = [];
        // 			for(var i=0;i<data.NetworkUsers.length;i++){
        // 				view.users[i] = {};
        // 				view.users[i].userId = data.NetworkUsers[i].UserId;
        // 				view.users[i].userName = data.NetworkUsers[i].UserName;
        // 				view.users[i].fullName = data.NetworkUsers[i].UserFullName;
        // 				view.users[i].emailId = data.NetworkUsers[i].EmailID;
        // 				view.users[i].flag = data.NetworkUsers[i].Flag;
        // 			}
        // 		}
        // 		return view;
        // 	}
        // },
        // @POST @Path("/Auth")
        // public String submit(User user)
        login:function(handler,request,errHandler){
            var domain = {};
            domain.UserID = request.userId;
            domain.Password = request.password;
            return sfw.Http.post(getUrl(7),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                UserID : request.userId,
                Password : request.password
            });
            function toViewModel(data){
                var view = {};
                view.token = data.AccessToken;
                view.code = data.ResponseCode;
                view.message = data.ResponseMessage;
                return view;
            }
        }
    }
})();

//@Path("/IWantTo")
Workport.WantAPI = (function(){
    var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'IWantTo/';

    var urls = ["HomeAppsList", "AppsList", "SearchHomeApps", "SearchApps","{1}/AddFavourite", "{1}/Tabs" ];

    function getUrl(/*index, replace1, replace2, ...*/) {
        var index, i, loops, r;
        loops = arguments.length;
        if (loops > 0) {
            index = arguments[0];
            r = root + urls[index];
            for (i = 1; i < loops; i++)
                r = r.replace("{"+i+"}", arguments[i]);
        }
        return r;
    }

    return {
        // @GET  @Path("/HomeAppsList")
        // public HomeAppResponse GetHomeApps()
        homeApps:function(handler,request){
            return sfw.Http.get(getUrl(0),function(xhr, data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                Offset:request.offset,
                Count:request.count,
                FilterBy:request.filterBy,
                orderBy:request.orderBy,
                Mode:request.mode
            });
        },
        // @GET	@Path("/AppsList")
        //public AppResponse GetApps()
        allApps:function(handler,request){
            return sfw.Http.get(getUrl(1),function(xhr, data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                Offset:request.offset,
                Count:request.count,
                FilterBy:request.filterBy,
                orderBy:request.orderBy,
                Mode:request.mode
            });
        },
        // @GET	@Path("/SearchHomeApps")
        // public AppResponse GetHomeAppsSearchResult()
        searchHomeApp:function(handler,request){
            return sfw.Http.get(getUrl(2),function(xhr, data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                Offset:request.offset,
                Count:request.count,
                SearchText:request.key,
                Filtermode:request.mode
            });
        },
        // @GET	@Path("/SearchApps")
        // public AppResponse GetAppsSearchResult()
        searchApp:function(handler,request){
            return sfw.Http.get(getUrl(3),function(xhr, data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                Offset:request.offset,
                Count:request.count,
                SearchText:request.key,
                Filtermode:request.mode
            });
        },
        // @GET	@Path("/{AppId}/AddFavourite")
        // public AddFavouriteResponse GetAddFavourite(@PathParam("AppId") int appID)
        addFavourite:function(handler,request){
            var url = "IWantTo/"+request.appId+"/AddFavourite";
            return sfw.Http.get(getUrl(4,request.appId),function(xhr, data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            });
        },
        // @GET	@Path("/{AppId}/Tabs")
        // public TabResponse GetTabs(@PathParam("AppId") int appID)
        getTabs:function(handler,request){
            var url = "IWantTo/"+request.appId+"/Tabs";
            return sfw.Http.get(getUrl(5,request.appId),function(xhr, data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            });
        }
    }
})();

// @Path("/Box")
Workport.BoxAPI = (function(){

    var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'Box/';

    var urls = ["CheckUserToken", "{1}", "{1}" ];

    function getUrl(/*index, replace1, replace2, ...*/) {
        var index, i, loops, r;
        loops = arguments.length;
        if (loops > 0) {
            index = arguments[0];
            r = root + urls[index];
            for (i = 1; i < loops; i++)
                r = r.replace("{"+i+"}", arguments[i]);
        }
        return r;
    }

    function sendGetRequest(url,callback,query,sync,data){
        if(sync){
            return sfw.Http.syncGet(url,callback,query);
        } else {
            return sfw.Http.get(url,callback,query);
        }
    }

    return {
        // @GET @Path("/CheckUserToken")
        // public BasicResponse CheckUserToken()
        checkToken:function(handler,request){
            return sendGetRequest(getUrl(0),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                code : request.code
            },request.sync );
        },
        // @GET		@Path("/{FolderId}")
        // public BoxItemResponse GetBoxItems(@PathParam("FolderId") String folderId)
        getItems:function(handler,request){
            return sendGetRequest(getUrl(1,request.folderId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                } else {
                    handler({ResponseCode:"WP2005"});
                }
            },{
                count:request.count,
                pid:request.pid,
                filter:request.filter
            },request.sync);
        },
        // @GET	@Path("/{ItemId}/EmbedUrl")
        // public EmbedUrlResponse GetEmbedUrl(@PathParam("ItemId") String itemId)
        getEmbedUrl:function(handler,request){
            return sendGetRequest(getUrl(2,request.itemId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },null,request.sync);
        }
    }
})();

//@Path("/Search")
Workport.SearchAPI = (function(){
    
    var root = 'Search';    
    var urls = ["","/Tag","/Community","/CommunityTag","/Advanced","/Trending","/Frequent"];
    var util = Workport.APIUtil;
    
    return {
        name : root,
        urls : urls,
        // @GET    @Path("/")
        // public SearchResponse GetGlobalSearch()
        search:function(handler,request){
            return util.sendRequest('get',util.getUrl(0,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                key:request.key,
                ps:request.ps,
                pn:request.pn
            },request.sync);
        },
        // @GET    @Path("/Tag")
        // public SearchResponse GetTagSearch()
        searchTag:function(handler,request){
            return util.sendRequest('get',util.getUrl(1,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                key:request.key,
                ps:request.ps,
                pn:request.pn
            },request.sync);
        },
        // @GET    @Path("/Community")
        // public SearchResponse GetCommunitySearch()
        searchCommunity:function(handler,request){
            return util.sendRequest('get',util.getUrl(2,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                key:request.key,
                ps:request.ps,
                pn:request.pn,
                cid:request.cid
            },request.sync);
        },
        // @GET    @Path("/CommunityTag")
        // public SearchResponse GetCommunityTagSearch()
        searchCommunityTag:function(handler,request){
            return util.sendRequest('get',util.getUrl(3,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                key:request.key,
                ps:request.ps,
                pn:request.pn,
                cid:request.cid
            },request.sync);
        },
        // @GET    @Path("/Advanced")
        // public SearchResponse GetAdvancedSearchResults()
        searchAdvanced:function(handler,request){
            return util.sendRequest('get',util.getUrl(4,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                ps:request.ps,
                pn:request.pn,
                all:request.all,
                exact:request.exact,
                any:request.any,
                none:request.none,
                offsetfrom:request.from,
                offsetto:request.to,
                authorVal:request.authorVal,
                cid:request.cid
            },request.sync);
        },
        //////////////////////////// search refine
     // @GET    @Path("/")
        // public SearchResponse GetGlobalSearch()
        searchRefine:function(handler,request){
            return util.sendRequest('get',util.getUrl(0,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
            	key:request.key,
                ps:request.ps,
                pn:request.pn,
                refAuthor:request.refAuthor,
                refDate:request.refDate,
                refTopic:request.refTopic
            },request.sync);
        },
        // @GET    @Path("/Tag")
        // public SearchResponse GetTagSearch()
        searchTagRefine:function(handler,request){
            return util.sendRequest('get',util.getUrl(1,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                key:request.key,
                ps:request.ps,
                pn:request.pn,
                refAuthor:request.refAuthor,
                refDate:request.refDate,
                refTopic:request.refTopic
            },request.sync);
        },
        // @GET    @Path("/Community")
        // public SearchResponse GetCommunitySearch()
        searchCommunityRefine:function(handler,request){
            return util.sendRequest('get',util.getUrl(2,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                key:request.key,
                ps:request.ps,
                pn:request.pn,
                cid:request.cid,
                refAuthor:request.refAuthor,
                refDate:request.refDate,
                refTopic:request.refTopic
            },request.sync);
        },
        // @GET    @Path("/CommunityTag")
        // public SearchResponse GetCommunityTagSearch()
        searchCommunityTagRefine:function(handler,request){
            return util.sendRequest('get',util.getUrl(3,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
                key:request.key,
                ps:request.ps,
                pn:request.pn,
                cid:request.cid,
                refAuthor:request.refAuthor,
                refDate:request.refDate,
                refTopic:request.refTopic
            },request.sync);
        },
        // @GET    @Path("/Advanced")
        // public SearchResponse GetAdvancedSearchResults()
        searchAdvancedRefine:function(handler,request){
            return util.sendRequest('get',util.getUrl(4,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
            	ps:request.ps,
                pn:request.pn,
                all:request.all,
                exact:request.exact,
                any:request.any,
                none:request.none,
                offsetfrom:request.from,
                offsetto:request.to,
                authorVal:request.authorVal,
                refAuthor:request.refAuthor,
                refDate:request.refDate,
                refTopic:request.refTopic,
                cid:request.cid
            },request.sync);
        },
        // @GET    @Path("/Trending")
        // public SearchWidgetResponse GetTrendingTopics()
        searchTrending:function(handler,request){
            return util.sendRequest('get',util.getUrl(5,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },null,request && request.sync);
        },
        // @GET    @Path("/Frequent")
        // public SearchWidgetResponse GetFrequentlySearch()
        searchFrequent:function(handler,request){
            return util.sendRequest('get',util.getUrl(6,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },null,request && request.sync);
        }
    }
})();


//@Path("/ProfileProperties")
Workport.ProfileAPI = (function(){   
	
    var root = 'ProfileProperties';    
    var urls = [ "/{1}" ];
    var util = Workport.APIUtil;
    
    return {
        name : root,
        urls : urls,
        // @GET    @Path("/{userid}")
        // public UserProfilePropertiesResponse getUserProperty(@PathParam("userid") String userid)
        getProperty:function(handler,request){
            return util.sendRequest('get',util.getUrl(0,this,request.userId),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },null,request.sync);
        }
    }
})();